class ForumsController < ApplicationController
  include AuthenticatedSystemBrowse
  
  def index
    @common_forums = CommonForum.find(:all)
    @new_topics = Topic.find(:all, :include => [:user, :forum ], :limit => 20, :order => "replied_at desc")
    @page_title = "论坛"
  end
  
  def search
    if params[:q].nil? || params[:q].blank?
      redirect_back_or_default forums_url
    else
      @topics = Topic.paginate_search(params[:q], {:page => params[:page]})
      @page_title = '搜索论坛话题 - ' + params[:q]
    end
  end
  
  def show
    @forum = Forum.find(params[:id])
    #@topics = Topic.paginate_by_forum_id @forum.id, :page => params[:page], :order => "replied_at DESC"
    @topics = @forum.topics.paginate :include => [:user, :forum ], :page => params[:page], :order => "replied_at DESC"
    if @forum.class == CommunityForum
      @page_title = @forum.community.district.title + ' - '+ @forum.community.title + " - 论坛"
    else
      @page_title = @forum.title + "论坛"
    end
  end
end
